<template>
  <div>
    <el-select style="display: block;" :size="size" v-model="value" placeholder="选择司机" clearable @change="changeValue"
               @clear="changeValue">
      <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"/>
    </el-select>
  </div>
</template>

<script>
import {isNotNull} from "@/util/common-util";

export default {
  name: "rehydration-vehicle-driver-select",
  props: {
    initValue: {
      type: Object,
      default: null
    },
    size: {
      type: String,
      default: 'small'
    }
  },
  data() {
    return {
      options: [],
      list: [],
      value: ''
    }
  },
  created() {
    this.initOptions(() => {
      if (isNotNull(this.initValue)) {
        this.value = this.initValue
      }
    })
  },
  methods: {
    initOptions(success) {
      this.options = [{
        label: 'xxxxx',
        value: 1
      }, {
        label: '222',
        value: 2
      }, {
        label: 'ssss',
        value: 3
      }, {
        label: 'ffff',
        value: 4
      }]
      this.list = [
        {id: 1, name: 'sssss1', phone: '1222222222'},
        {id: 2, name: 'sssss2', phone: '1222222223'},
        {id: 3, name: 'sssss3', phone: '12222222423'},
        {id: 4, name: 'sssss4', phone: '1222222252'}
      ]
      success && success()
    },
    changeValue() {
      for (const item of this.list) {
        if (item.id === this.value) {
          this.$emit('change', item)
          return
        }
      }
      this.$emit('change', {})
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
